

<?php
	//function

	include_once "global.php";
	include_once "../public/c_mysql_db.inc.php";

	//$_POST['s'] ="eyJJTUd0YWxrIjpbeyJTZW5kIjowLCJSZWN2QiI6MCwiU2VuZEIiOjAsIlJlY3YiOjAsIkFjY291bnQiOiJ5dWNoZHJvaWRAZ21haWwuY29tIn1dLCJUaW1lIjoxMzE1OTgzOTMxLCJFbWFpbCI6W10sIkdFTyI6W3sidCI6MTMxNTk4MzkzMSwieSI6MCwieCI6MH0seyJ0IjoxMzE1OTgzOTMxLCJ5IjowLCJ4IjowfV0sIldlaWJvUVEiOltdLCJXZWlib1QiOltdLCJJRCI6Iui/meaYr+S4reaWh+a1i+ivlVRlc3QtLTEiLCJXZWlib1NpbmEiOltdfQ==";
	$datetime = date("Y:m:d H:i:s");
	$date = date("Ymd");
	

	if (!$fd = fopen("./report{$date}.log", "a+"))
	{
		echo "[{$date}] can't open file";
		exit;
	}

	//base64_decode()
	if (isset($_POST['s']))
	{
		$report_info_json = base64_decode($_POST['s']);	

		//write to db
		//db init
		$db = new c_mysql_db(DB_USER, DB_PASS, DB_HOST, DB_NAME);
		$sql = "insert into YBM_raw_data values(null, '{$_POST['s']}',".
				"'{$report_info_json}', ADDDATE(now(), INTERVAL 14 HOUR), ".
				"'{$_SERVER['REMOTE_ADDR']}', {$_SERVER['REMOTE_PORT']})";

		$rs = $db->query("set names utf8");
		$rs = $db->query($sql);
	} 
	else
	{	
		fclose($fd);
		echo "<H1>403 FORBIDDEN</H1> ";
		exit;
	}

	$db->logoff();

	fclose($fd);
	echo ("OK");

?>
